home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / adduser.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  9KB  |  375 lines

  1. /*
  2.  *                AddUser.C
  3.  *
  4.  * Adds a user to a C86 installation.
  5.  */
  6.  
  7. /*
  8.  *                History
  9.  *
  10.  * 90Dec28  HAW V1 Created.
  11.  */
  12.  
  13. /*
  14.  *                Contents
  15.  *
  16.  *    main()            main manager
  17.  *    ShowArguments()        Usage stuff
  18.  *    ParseFile()        parses the input file
  19.  *    OnOff()            parses an On/Off parameter
  20.  *    AddAccount()        adds a new account to the system
  21.  *    slideLTab()        inserts account into logTab
  22.  *    storeLog()        stores the current log record
  23.  *    crashout()        fatal error handler
  24.  */
  25.  
  26. #include "ctdl.h"    /* header file  */
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <math.h>
  31. #include <ctype.h>
  32. #include <time.h>
  33. #include <proto/exec.h>
  34. #include <dos/dos.h>
  35. #include <pragmas/dos_pragmas.h>
  36. #include "exec/memory.h"
  37. #include "exec/ports.h"
  38. #include "exec/exec.h"
  39.  
  40. #define AU_COPYRIGHT "Copyright (c) 1990, 1992 by Hue, Jr."
  41.  
  42. extern CONFIG     cfg;            /* A buncha variables */
  43. extern logBuffer logBuf;        /* Pippul buffer */
  44. extern logBuffer logTmp;        /* Pippul buffer */
  45. extern FILE     *logfl;        /* log file descriptor */
  46. extern LogTable     *logTab;
  47. extern int     thisLog;
  48. extern rTable     *roomTab;        /* RAM index of rooms */
  49.  
  50. void ShowArguments(void);
  51. void ParseFile(void);
  52. void AddAccount(void);
  53. char OnOff(char *where);
  54.  
  55. FILE *fd;
  56. char onConsole, remoteSysop;
  57.  
  58. /*
  59.  * main()
  60.  *
  61.  * This is the main manager for adduser.
  62.  */
  63. int main(int, char **);
  64. int main(argc, argv)
  65. int  argc;
  66. char **argv;
  67. {
  68.     SYS_FILE tempName;
  69.  
  70.     printf("AddUser V3.41\n%s\n", AU_COPYRIGHT);
  71.  
  72.     if (argc != 2) {
  73.         ShowArguments();
  74.         exit(1);
  75.     }
  76.  
  77.     if ((fd = fopen(argv[1], "r")) == NULL) {
  78.         printf("Couldn't open %s.\n", argv[1]);
  79.         exit(1);
  80.     }
  81.  
  82.     if (!readSysTab(FALSE, TRUE)) exit(1);
  83.  
  84.     makeSysName(tempName, "ctdllog.sys",  &cfg.logArea);
  85.     openFile(tempName, &logfl );
  86.  
  87.     initLogBuf(&logBuf);
  88.     initLogBuf(&logTmp);
  89.  
  90.     ParseFile();
  91.  
  92.     AddAccount();
  93.  
  94.     writeSysTab();
  95.  
  96.     return 0;
  97. }
  98.  
  99. /*
  100.  * ShowArguments()
  101.  *
  102.  * This function shows the arguments for adduser.
  103.  */
  104. void ShowArguments()
  105. {
  106.     printf("Usage: adduser <filename>\n\n");
  107.   printf("The format of the file should be as follows\n\n");
  108.   printf("User name (string)\n");
  109.   printf("Password (string)\n");
  110.   printf("Screen width (numeric, in columns)\n");
  111.   printf("Expert setting (ON or OFF)\n");
  112.   printf("Floor setting (ON or OFF)\n");
  113.   printf("Linefeeds setting (ON or OFF)\n");
  114.   printf("Display Time on messages (ON or OFF)\n");
  115.   printf("Last Old on New toggle (ON or OFF)\n");
  116.   printf("\t<last line of required data>\n");
  117.   printf("\t<following data is optional>\n");
  118.   printf("Aide setting (ON or OFF) (default to OFF)\n");
  119.   printf("Number of NULLS (numeric) (default 0)\n");
  120.   printf("Number of LD credits (numeric) (default 0)\n");
  121.   printf("Net privileges (ON or OFF) (default OFF)\n");
  122.   printf("Door privileges (ON or OFF) (default OFF)\n");
  123.   printf("Download privileges (ON or OFF) (default OFF)\n");
  124.   printf("Permanent account (ON or OFF) (default OFF)\n");
  125.   printf("Half Duplex setting (ON or OFF) (default OFF)\n");
  126.   printf("Twit setting (ON or OFF) (default OFF)\n");
  127.   printf(".ECD setting (numeric) (default 0)\n");
  128.   printf(".ECZ setting (ON or OFF) (defaults to OFF)\n");
  129. }
  130.  
  131. char Required = TRUE;
  132. /*
  133.  * ParseFile()
  134.  *
  135.  * This function parses the input file.
  136.  */
  137. void ParseFile(void)
  138. {
  139.     char line[200], good;
  140.     int  i, h;
  141.  
  142.     zero_struct(logBuf.lbflags);    /* zero all flags    */
  143.     /* user name */
  144.     if (GetAString(line, sizeof line, fd) == NULL)
  145.         crashout("File ended abruptly while reading username.");
  146.  
  147.     if (strLen(line) == 0)
  148.         crashout("Name is not long enough.");
  149.  
  150.     if (strLen(line) > 19)
  151.         crashout("Name is too long.");
  152.  
  153.     if (PersonExists(line) != ERROR)
  154.         crashout("Person already exists.");
  155.  
  156.     strCpy(logBuf.lbname, line);
  157.  
  158.     /* User password */
  159.     if (GetAString(line, sizeof line, fd) == NULL)
  160.         crashout("File ended abruptly while reading password.");
  161.  
  162.     if (strLen(line) < 3)
  163.         crashout("Password is not long enough.");
  164.  
  165.     if (strLen(line) > 19)
  166.         crashout("Password is too long.");
  167.  
  168.     h = hash(line);
  169.     for (i = 0, good = TRUE; i < cfg.MAXLOGTAB && good; i++) {
  170.         if (h == logTab[i].ltpwhash) good = FALSE;
  171.     }
  172.  
  173.     if (!good)
  174.         crashout("Password already exists.");
  175.  
  176.     strCpy(logBuf.lbpw, line);
  177.  
  178.     if (GetAString(line, sizeof line, fd) == NULL)
  179.         crashout("File ended abruptly while reading screen width.");
  180.  
  181.     if (!isdigit(line[0]))
  182.         crashout("The screen width doesn't seem to be a numeral.");
  183.  
  184.     logBuf.lbwidth = atoi(line);
  185.     logBuf.lbflags.EXPERT = OnOff("Expert setting");
  186.     logBuf.lbflags.FLOORS = OnOff("Floors setting");
  187.     logBuf.lbflags.LFMASK = OnOff("Linefeeds setting");
  188.     logBuf.lbflags.TIME = OnOff("Time setting");
  189.     logBuf.lbflags.OLDTOO = OnOff("Old on New display setting");
  190.     Required = FALSE;
  191.     logBuf.lbflags.AIDE = OnOff("Aide setting");
  192.  
  193.     /* NULLs */
  194.     if (GetAString(line, sizeof line, fd) != NULL) {
  195.  
  196.         if (!isdigit(line[0]))
  197.             crashout("The NULLs value doesn't seem to be a numeral.");
  198.         logBuf.lbnulls = atoi(line);
  199.     }
  200.     else logBuf.lbnulls = 0;
  201.  
  202.     /* LD credits */
  203.     if (GetAString(line, sizeof line, fd) != NULL) {
  204.  
  205.         if (!isdigit(line[0]))
  206.             crashout("The NULLs value doesn't seem to be a numeral.");
  207.         logBuf.credit = atoi(line);
  208.     }
  209.     else logBuf.credit = 0;
  210.  
  211.     logBuf.lbflags.NET_PRIVS = OnOff("Net privs setting");
  212.     logBuf.lbflags.DOOR_PRIVS = OnOff("Door privs setting");
  213.     logBuf.lbflags.DL_PRIVS = OnOff("DL privs setting");
  214.     logBuf.lbflags.PERMANENT = OnOff("Permanent account setting");
  215.     logBuf.lbflags.HALF_DUP = OnOff("Half-duplex setting");
  216.     logBuf.lbflags.TWIT = OnOff("Twit setting");
  217.  
  218.     /* Delay stuff */
  219.     if (GetAString(line, sizeof line, fd) != NULL) {
  220.  
  221.         if (!isdigit(line[0]))
  222.             crashout("The delay value doesn't seem to be a numeral.");
  223.         logBuf.lbdelay = atoi(line);
  224.     }
  225.     else logBuf.lbdelay = 0;
  226.     logBuf.lbflags.ALT_RE = OnOff(".ECZ setting");
  227. }
  228.  
  229. /*
  230.  * OnOff()
  231.  *
  232.  * This handles parsing an On/Off parameter.  If interpretation fails it
  233.  * crashes out.
  234.  */
  235. char OnOff(char *where)
  236. {
  237.     char line[200];
  238.  
  239.     if (GetAString(line, sizeof line, fd) == NULL) {
  240.         sprintf(line, "File ended abruptly while reading %s.", where);
  241.         crashout(line);
  242.     }
  243.  
  244.     if (stricmp(line, "on") == SAMESTRING)
  245.         return TRUE;
  246.     if (stricmp(line, "off") == SAMESTRING)
  247.         return FALSE;
  248.  
  249.     if (Required) {
  250.         sprintf(line, "Malformed value for %s.", where);
  251.         crashout(line);
  252.     }
  253.  
  254.     return FALSE;
  255. }
  256.  
  257. /*
  258.  * AddAccount()
  259.  *
  260.  * This function adds a new account to the system.
  261.  */
  262. void AddAccount()
  263. {
  264.     int good, ourSlot, i, g;
  265.     MSG_NUMBER  low;
  266.     char tmp[30];
  267.     SYS_FILE    checkHeld;
  268.     char   *LCHeld = "log%d.hld";
  269.  
  270.     for (good = cfg.MAXLOGTAB-1; good >= 0; good--)
  271.         if (!logTab[good].ltpermanent) break;
  272.  
  273.     if (good < 0) good = cfg.MAXLOGTAB - 1;    /* too bad */
  274.  
  275.     ourSlot    = logTab[good].ltlogSlot;
  276.  
  277.     slideLTab(0, good);
  278.     logTab[0].ltlogSlot = ourSlot;
  279.  
  280.     thisLog = ourSlot;
  281.  
  282.     /* copy info into record:       */
  283.     logBuf.lbflags.L_INUSE    = TRUE;
  284.  
  285.     low = cfg.newest-50;
  286.     if (cfg.oldest - low < 0x8000)   low = cfg.oldest;
  287.     for (i=1;  i<MAXVISIT;  i++)   logBuf.lbvisit[i]= low;
  288.     logBuf.lbvisit[    0]= cfg.newest;
  289.     logBuf.lbvisit[    (MAXVISIT-1)]= cfg.oldest;
  290.  
  291.     /* initialize rest of record:   */
  292.     for (i = 0;  i < MAXROOMS;  i++) {
  293.         if (roomTab[i].rtflags.PUBLIC == 1) {
  294.         g = (roomTab[i].rtgen);
  295.         logBuf.lbgen[i] = (g << GENSHIFT) + (MAXVISIT-1);
  296.         } else {
  297.         /* set to one less */
  298.         g = (roomTab[i].rtgen + (MAXGEN-1)) % MAXGEN;
  299.         logBuf.lbgen[i] = (g << GENSHIFT) + (MAXVISIT-1);
  300.         }
  301.     }
  302.     memset(logBuf.lbMail, 0, MAIL_BULK);
  303.  
  304.     /* fill in logTab entries       */
  305.     i = 0;
  306.     logTab[i].ltpwhash      = hash(logBuf.lbpw)  ;
  307.     logTab[i].ltnmhash      = hash(logBuf.lbname);
  308.     logTab[i].ltlogSlot     = ourSlot    ;
  309.     logTab[i].ltnewest      = logBuf.lbvisit[0];
  310.     logTab[i].ltpermanent   = logBuf.lbflags.PERMANENT;
  311.  
  312. #ifdef MAIL_ALSO
  313.     /* automatic mail for the new user. */
  314.     makeSysName(checkHeld, (logBuf.lbflags.EXPERT) ? "expmail.blb" :
  315.                     "novmail.blb", &cfg.homeArea);
  316.     if (access(checkHeld, 0) == 0) {
  317.         i = thisRoom;
  318.         getRoom(MAILROOM);
  319.         ZeroMsgBuffer(&msgBuf);
  320.         ingestFile(checkHeld, &msgBuf);
  321.         strCpy(msgBuf.mbauth, (strLen(cfg.SysopName)) ?
  322.                     cfg.SysopName : "Citadel");
  323.         strCpy(msgBuf.mbto, logBuf.lbname);
  324.         putMessage(lBuf);
  325.         getRoom(i);
  326.     }
  327. #endif
  328.  
  329.     storeLog();
  330.  
  331.     if (cfg.BoolFlags.HoldOnLost) {
  332.         sprintf(tmp, LCHeld, ourSlot);
  333.         makeSysName(checkHeld, tmp, &cfg.holdArea);
  334.         unlink(checkHeld);
  335.     }
  336. }
  337.  
  338. /*
  339.  * slideLTab()
  340.  *
  341.  * This function slides bottom N lots in logTab down.  For sorting.
  342.  */
  343. void slideLTab(int slot, int last)
  344. {
  345.     int i;
  346.  
  347.     /* open slot up: (movmem isn't guaranteed on overlaps) */
  348.     for (i = last - 1;  i >= slot;  i--)  {
  349.     memcpy(&logTab[i + 1], logTab + i, cfg.sizeLTentry);
  350.     }
  351. }
  352.  
  353. /*
  354.  * storeLog()
  355.  *
  356.  * This function stores the current log record.
  357.  */
  358. void storeLog()
  359. {
  360.     logTab[0].ltnewest    = cfg.newest;
  361.     logBuf.lbvisit[0]     = cfg.newest;
  362.     putLog(&logBuf, thisLog);
  363. }
  364.  
  365. /*
  366.  * crashout()
  367.  *
  368.  * Fatal error?  Out we go!
  369.  */
  370. void crashout(char *s)
  371. {
  372.     printf("Ooops: %s\n", s);
  373.     exit(1);
  374. }
  375.